package com.javasm.controller.goods;


import com.javasm.common.http.AxiosResult;
import com.javasm.common.page.PageResult;
import com.javasm.common.valid.addGroup;
import com.javasm.controller.base.BaseController;
import com.javasm.domin.criteria.goods.ActivityCriteria;
import com.javasm.domin.criteria.goods.GoodsAdjustCriteria;
import com.javasm.domin.entity.goods.Activity;
import com.javasm.domin.entity.goods.Goods;
import com.javasm.domin.entity.goods.GoodsAdjust;
import com.javasm.domin.vo.goods.ActivityVo;
import com.javasm.domin.vo.goods.GoodsAdjustVo;
import com.javasm.service.goods.IActivityService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author whl
 * @since 2022-01-16
 */
@RestController
@RequestMapping("activity")
@RequiredArgsConstructor
public class ActivityController extends BaseController {

    private  final IActivityService iActivityService;
    /**
     * 分页条件查询
     */
    @GetMapping
    public AxiosResult<PageResult<ActivityVo>> list(ActivityCriteria activityCriteria  ) {
        PageResult<ActivityVo> list = iActivityService.searchPage(activityCriteria);
        return AxiosResult.success(list);
    }


    /**
     * 分页条件查询
     */
    @GetMapping("findByApproveStatus")
    public AxiosResult<PageResult<ActivityVo>> list2(ActivityCriteria activityCriteria  ) {
        PageResult<ActivityVo> list = iActivityService.searchPage1(activityCriteria);
        return AxiosResult.success(list);
    }

    /**
     * 添加
     */
    @PostMapping
    public AxiosResult<Void> add(@Validated(addGroup.class) @RequestBody Activity activity) {

        return toAxios(iActivityService.save(activity));
    }



    /**
     * 根据id查询
     */
    @GetMapping("{id}")
    public AxiosResult<Activity> findById(@PathVariable Long id) {
        Activity byId = iActivityService.getById(id);

        return AxiosResult.success(byId);
    }


    /**
     * 修改
     */
    @PutMapping
    public AxiosResult<Void> update(@RequestBody Activity activity) {
        return toAxios(iActivityService.update(activity));
    }

    /**
     * 删除
     */
    @DeleteMapping("{id}")
    public AxiosResult<Void> delete(@PathVariable Long id) {
        return toAxios(iActivityService.deleteById(id));
    }


    /**
     * 批量删除
     */
    @DeleteMapping("batch/{ids}")
    public AxiosResult<Void> batch(@PathVariable List<Long> ids) {
        return toAxios(iActivityService.batchDeleteByIds(ids));
    }
}
